<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentCancelAccount.class.php, $Author:  $ */



/** Cancel account
 *
 * Parameters:
 *  1. oUser (required) - user account object
 *
 * @package module.account
 * @version $Id: PhpFox_ComponentCancelAccount.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *
 */
class PhpFox_Mod_Account_ComponentCancelAccount extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    if (!App::getSetting('member_delete'))
	    {
	        return App::format('Mod_Account.section_disabled');
	    }

	    $oAcc = $this->getParam('oUser');
	    /* @var $oAcc PhpFox_Mod_Account_ItemAccount */
	    assert($oAcc != null);

	    $oSrvAcc = &$this->_oModule->getService('Account');
	    /* @var $oSrvAcc PhpFox_Mod_Account_ServiceAccount */

	    $oReq = &App::getRequest();
	    /* @var $oReq Request */

	    // processing
        switch($oReq->getAction())
        {
            case 'cancel_account':
                if ($oAcc->aData['password'] != md5($oReq->get('pass')))
                {
                    $this->addErrors(App::format('Mod_Account.error.wrong_password'));
                }
                else
                {
                    $oSrvAcc->delete($oAcc->getId());
                    App::gotoUrl('public.login');
                }
                break;
        }


		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assignSrc(array(
			'aErrors' => $this->getErrors(),
		));
		$srcHtml = $oTpl->fetch('CancelAccount.html');
		return $srcHtml;
	}

}
?>